{% macro pub(x) -%}
  {% if x.type == 'journals' %}

    <span class="authors">{{x.authors|authors}}</span>.
    <span class="title">{{x.title.strip(". ")}}</span>.
    <span class="journal">{{x.journal}}</span>,
    {% if x.volume or x.number %}
      {% if x.volume %} Volume {{x.volume}} {% endif %}
      {% if x.number %} ({{x.number}}) {% endif %}
      ,
    {% endif %}
    pp {{x.pages}}, {{x.year}}.

  {% elif x.type == 'conferences' %}

    <span class="authors">{{x.authors|authors}}</span>.
    <span class="title">{{x.title}}</span>.
    In {{x.inproceeding}}. pp. {{x.pages|isnull}}.
    ({{x.conference}}), {{x.location}}, {{x.year}}.

  {% elif x.type == 'book chapters' %}

    <span class="authors">{{x.authors|authors}}</span>.
    <span class="title">{{x.title}}</span>.
    {% if x.chapter %} Chapter {{x.chapter}} {% endif %}
    In {{x.booktitle}}, {{x.publisher}}. pp {{x.pages}}.
    Edited by {{x.editor|authors}}.  

  {% elif x.type == 'books' %}

    <span class="authors">{{x.authors|authors}}</span>.
    <span class="title">{{x.title}}</span>.
    <span class="publisher">Published by {{x.publisher}}, {{x.year|isnull}}</span>

  {% elif 'prep' in x.type %}

    <span class="authors">{{x.authors|authors}}</span>.
    <span class="title">{{x.title}}</span>.
    {{x.month|month}} {{x.year}}.

  {% else %}
    Unknown: {{x}}
  {% endif %}
  {% if x.note %} <span class="note">{{x.note}}</span> {% endif %}
  
{%- endmacro %}

{% macro talk(x) -%}
  <span class="authors">{{x.speakers}}</span>,
  <span class="title">{{x.title}}</span>.
  {% if x.event %} {{x.event}}. {% endif %}
  <span class="date">{{x.date}}</span>,
  <span class="location">{{x.location}}</span>
  {% if x.note %} <span class="note">{{x.note}}</span> {% endif %}
{%- endmacro %}

{% macro course(x) -%}
  <span class="coursecode">{{x.code|upper}}</span>
  <span class="title">{{x.title}}</span>
  {% if x.note %} <span class="note">({{x.note}})</span> {% endif %}
{%- endmacro %}

{% macro student(x) -%}
  <td class="name"> 
    {{x.lastname}}, {{x.firstname}}, {{x.type|degree}}
    {% if x.past %}, ({{x.end.strftime("%Y")}}) {% endif %}
  </td>
  <td class="thesistitle"> 
     {{x.thesistitle|isnull}}
     {% if x['co-supervision'] %}
     <span class="note">
       (co-supervision with {{x['co-supervision']}})
     </span>
     {% endif %}
  </td>
{%- endmacro %}

{% macro grant(x) -%}
  <span class="title">{{x.title}}</span> ({{x.yearstart}} - {{x.yearend}}),
  <span class="institution">{{x.grantinginstitution}}</span>,
  <span class="role">{{x.role}}</span>
  {% if x.note %} <span class="note">({{x.note}})</span> {% endif %}
{%- endmacro %}
{% macro grant2(x) -%}
  <td>{{x.title}}</td>
  <td>{{x.yearstart}} - {{x.yearend}}</td>
  <td>{{x.grantinginstitution}}</td>
  <td>{{x.role}}</td>
  <td>{{x.totalamount|money}}</td>
  <td>{% if x.note %} <span class="note">({{x.note}})</span> {% endif %}</td>
{%- endmacro %}
